home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-08-29 | 4.3 KB | 144 lines | [TEXT/PJMM] |
- unit MyAppleEvents;
-
- interface
-
- {$IFC undefined THINK_Pascal}
- uses
- Types;
- {$ENDC}
-
- const
- keyOdocOption = 'auto'; { optional parameter to open }
-
- var
- odoc_with_option: boolean;
-
- function InitAppleEvents (DoOApp, DoODoc, DoPrint, DoQuit: Ptr): OSErr;
- { function DoOApp: OSErr }
- { function DoODoc (fs: FSSpec): OSErr }
- { function DoPrint (fs: FSSpec): OSErr }
- { function DoQuit: OSErr}
-
- implementation
-
- uses
- {$IFC undefined THINK_Pascal}
- OSEvents,
- {$ENDC}
- EPPC, Notification, AppleEvents, MyAEUtils;
-
- function DoOApp (p: ptr): OSErr;
- inline
- $205F, $4E90;
-
- function DoDocs (fs: FSSpec; p: ptr): OSErr;
- inline
- $205F, $4E90;
-
- function DoQuit (p: ptr): OSErr;
- inline
- $205F, $4E90;
-
- const
- kPatienceLevel = 1000; { <aevt> ticks we wait for response }
- kSysEnvironsVersion = 1;
- kOSEvent = app4Evt; {event used by MultiFinder}
- kSuspendResumeMessage = 1; {high byte of suspend/resume event message}
- kResumeMask = 1; {bit of message field for resume vs. suspend}
- kMouseMovedMessage = $FA; {high byte of mouse-moved event message}
- kNoEvents = 0; {no events mask}
- kNoListChosen = -1;
-
- function HandleOAPP (event, reply: AppleEvent; openappp: ptr): OSErr;{ <aevt> }
- var
- oe: OSErr;
- begin
- { We don't expect any params at all, but check in case the client requires any }
- oe := GotRequiredParams(event);
- oe := DoOApp(openappp);
- HandleOAPP := oe;
- end;
-
- function HandleDocs (event, reply: AppleEvent; dodocp: ptr): OSErr; { <aevt> }
- var
- myFSS: FSSpec;
- docList: AEDescList;
- index, itemsInList: LONGINT;
- actualSize: Size;
- keywd: AEKeyword;
- typeCode: descType;
- oe, ooe, err: OSErr;
- er: EventRecord;
- realType: DescType;
- realSize: longInt;
- psn: ProcessSerialNumber;
- pi: ProcessInfoRec;
- begin
- err := GetBooleanFromAERecord(event, keyOdocOption, odoc_with_option);
- if err <> noErr then begin
- odoc_with_option := false;
- err := AEGetAttributePtr(event, keyAddressAttr, keyProcessSerialNumber, realType, @psn, SizeOf(psn), realSize);
- if err = noErr then begin
- pi.processInfoLength := sizeof(ProcessInfoRec);
- pi.processName := nil;
- pi.processAppSpec := nil;
- err := GetProcessInformation(psn, pi);
- end;
- if (err = noErr) & (pi.processSignature = 'MACS') then begin
- odoc_with_option := OSEventAvail(everyEvent, er);
- odoc_with_option := BAND(er.modifiers, optionKey) <> 0;
- end;
- end;
- oe := AEGetParamDesc(event, keyDirectObject, typeAEList, docList);
- if oe = noErr then begin
- ooe := GotRequiredParams(event);
- { now get each alias from the list (as an FSSSpec) and open the associated file. }
- oe := AECountItems(docList, itemsInList);
- for index := 1 to itemsInList do begin
- ooe := AEGetNthPtr(docList, index, typeFSS, keywd, typeCode, @myFSS, sizeof(myFSS), actualSize);
- { coercion does alias->fsspec }
- if ooe = noErr then
- ooe := DoDocs(myFSS, dodocp);
- end;
- ooe := AEDisposeDesc(docList);
- end;
- HandleDocs := oe;
- end; { HandleDocs }
-
- function HandleQUIT (event, reply: AppleEvent; quitp: ptr): OSErr; { <aevt> }
- var
- oe: OSErr;
- errStr: Str255;
- begin
- { We don't expect any params at all, but check in case the client requires any }
- oe := GotRequiredParams(event);
- oe := DoQuit(quitp); { set global boolean: app will exit at end of event loop }
- if reply.dataHandle <> nil then { a reply is sought }
- begin
- if oe = noErr then
- errStr := 'OK'
- else
- errStr := 'user cancelled quit';
- oe := AEPutParamPtr(reply, 'errs', 'TEXT', Ptr(@errStr[1]), length(errStr));
- end;
- HandleQUIT := oe;
- end;
-
- {$S Init}
- function InitAppleEvents (DoOApp, DoODoc, DoPrint, DoQuit: Ptr): OSErr;
- var
- aevtErr: OSErr;
- begin
- aevtErr := noErr;
- if (aevtErr = noErr) and (DoOApp <> nil) then
- aevtErr := AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, @HandleOAPP, longInt(DoOApp), false);
- if (aevtErr = noErr) and (DoODoc <> nil) then
- aevtErr := AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, @HandleDocs, longInt(DoODoc), false);
- if (aevtErr = noErr) and (DoPrint <> nil) then
- aevtErr := AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, @HandleDocs, longInt(DoPrint), false);
- if (aevtErr = noErr) and (DoQuit <> nil) then
- aevtErr := AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, @HandleQUIT, longInt(DoQuit), false);
- InitAppleEvents := aevtErr;
- end;
-
- end.